package org.tinygroup.trans.common;

import com.google.common.util.concurrent.RateLimiter;

public class RateLimitFilter {
	private Double rateLimit;
	RateLimiter rateLimiter;

	public boolean check() {
		if (rateLimiter != null && !rateLimiter.tryAcquire()) {
			return false;
		}
		return true;
	}

	public Double getRateLimit() {
		return rateLimit;
	}

	public void setRateLimit(Double rateLimit) {
		this.rateLimit = rateLimit;
		if (rateLimit != null) {
			rateLimiter = RateLimiter.create(rateLimit);
		}
	}

}
